#!/bin/bash

############################################################
# Run this script on the gateway 192.168.6.x
# Do the following on the device wich wants to use the gateway
# sudo route add -net 192.168.6.0 netmask 255.255.255.0 gw 192.168.6.x 
# add 'gateway 192.168.6.x' to /etc/network/interfaces
# By Hossein Shafagh
############################################################

call_iptables() {
	iptables -$1 FORWARD -o eth1 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
	iptables -$1 FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
	iptables -$1 POSTROUTING -t nat -j MASQUERADE 
}

case "$1" in
	start)
		call_iptables "A"
		;;
	stop)
		call_iptables "D"
		;;
	*)
		echo "Usage: $0 <start|stop>"
esac
